package com.bh.ly.oa.adapter;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bh.ly.oa.R;

public class OrderDetailContentlistAdapter extends BaseAdapter {
	Context context = null;
	List<JSONObject> array = null;

	// JSONObject jd;

	public OrderDetailContentlistAdapter(Context contex) {
		this.context = contex;
	}

	public List<JSONObject> getArray() {
		return array;
	}

	public void setArray(List<JSONObject> array) {
		this.array = array;
	}

	@Override
	public int getCount() {
		return array.size();
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		OrderItem orderItem = null;
		if (convertView == null) {
			orderItem = new OrderItem();
			convertView = LayoutInflater.from(context).inflate(R.layout.order_content_detail_item, null);
		} else {
			orderItem = (OrderItem) convertView.getTag();
		}

		JSONObject jsonObject = (JSONObject) array.get(position);
		initView(position, convertView, orderItem);
		try {
			orderItem.gdsname.setText(jsonObject.get("gdsname").toString());
			orderItem.amount.setText(jsonObject.get("amount").toString());
			orderItem.inprice.setText(jsonObject.get("inprice").toString());
			orderItem.amount.setText(jsonObject.get("amount").toString());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return convertView;
	}

	private void initView(int position, View convertView, OrderItem orderItem) {
		orderItem.gdsname = (TextView) convertView.findViewById(R.id.gdsname);
		orderItem.amount = (TextView) convertView.findViewById(R.id.amount);
		orderItem.inprice = (TextView) convertView.findViewById(R.id.inprice);
		orderItem.inmoney = (TextView) convertView.findViewById(R.id.inmoney);
		convertView.setTag(orderItem);
	}

	class OrderItem {
		TextView gdsname;
		TextView amount;
		TextView inprice;
		TextView inmoney;
	}

}
